Add a new item to a store.
Parent Type: LearningStoreJob
Namespace: Microsoft.LearningComponents.Storage
Assembly: Microsoft.LearningComponents.Storage.dll
| C# |
|
public LearningStoreItemIdentifier AddItem ( ) |
itemTypeName
The name of the item type to add
propertyValues
Property values for the item. The key is the property name, and the value is the value to be placed in the property.
requestItemId
If true, a LearningStoreItemIdentifier for the newly-added item in the store will be returned in the results.
A temporary LearningStoreItemIdentifier that identifies the item being added. This value may be used to reference the item in other commands in this job, but it becomes invalid after the job has been executed. To retrieve a LearningStoreItemIdentifier that is valid after the job has been executed, call this method with requestItemId=true, and the LearningStoreItemIdentifier will be returned as one of the results of the job.
| Exception type | Condition |
| ArgumentNullException | itemTypeName or propertyValuesis a null reference. |
| System.InvalidOperationException | The item type in itemTypeName doesn't exist in the store, a property name passed in propertyValues doesn't exist on the item type, a property value passed in propertyValues is not a valid value for the corresponding property, or a required property wasn't passed in propertyValues. |
Steps required to add a new item to a store:
This operation returns a LearningStoreItemIdentifier as a result if requestItemId is true. It returns nothing as a result if requestItemId is false.
The following code adds a new user item to the store specified by "store":
| C# |
// Create the property values
Dictionary<string,object> propertyValues = new Dictionary<string,object>();
propertyValues["Name"] = "John Doe";
propertyValues["Key"] = "Company\JohnDoe";
// Create a job and add the "add item" operation
LearningStoreJob job = store.CreateJob();
job.AddItem("UserItem", propertyValues, false);
// Execute the job
job.Execute();
|
| C# |
// Create the property values
Dictionary<string,object> propertyValues = new Dictionary<string,object>();
propertyValues["Name"] = "John Doe";
propertyValues["Key"] = "Company\JohnDoe";
// Create a job and add the "add item" operation
LearningStoreJob job = store.CreateJob();
job.AddItem("UserItem", propertyValues, true);
// Execute the job, asking for a Id to be returned
LearningStoreItemIdentifier id = job.Execute<LearningStoreItemIdentifier>();
|
| C# |
// Create the job
LearningStoreJob job = store.CreateJob();
// Add the first "add" operation that adds the user
Dictionary<string,object> propertyValues = new Dictionary<string,object>();
propertyValues["Name"] = "John Doe";
propertyValues["Key"] = "Company\JohnDoe";
LearningStoreItemIdentifier newUserId = job.AddItem("UserItem", propertyValues, true);
// Add the second "add" operation that adds the global objective
propertyValues = new Dictionary<string,object>();
propertyValues["Key"] = "MyGlobalObjective";
propertyValues["Description"] = "MyGlobalObjective Description";
LearningStoreItemIdentifier newGlobalObjectiveId = job.AddItem("GlobalObjectiveItem", propertyValues, true);
// Add the third "add operation" that adds the learner global objective
propertyValues = new Dictionary<string,object>();
propertyValues["LearnerId"] = newUserId;
propertyValues["GlobalObjectiveId"] = newGlobalObjectiveId;
job.AddItem("LearnerGlobalObjectiveItem", propertyValues, true);
// Execute the job, which adds all the items
ReadOnlyCollection<object> results = job.Execute();
|